package com.lzw.bluetoothpractice.Activitys;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.widget.Toast;

import com.lzw.bluetoothpractice.Adapters.HealthyMessagesAdapter;
import com.lzw.bluetoothpractice.Adapters.MyCollectionAdapter;
import com.lzw.bluetoothpractice.Models.Article;
import com.lzw.bluetoothpractice.Models.Collect;
import com.lzw.bluetoothpractice.Models._User;
import com.lzw.bluetoothpractice.R;

import java.util.List;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.http.bean.Init;
import cn.bmob.v3.listener.FindListener;

public class MyCollectionActivity extends BaseActivity {


    private MyCollectionAdapter myCollectionAdapter;
    private RecyclerView rc_collection;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_collection);
        InitNavBar(true,"我的收藏",false);
        InitView();
        InitData();
    }
    public void  InitView(){
        rc_collection=fd(R.id.rv_collection);
    }
    public void InitData(){
        BmobQuery<Collect> query1 = new BmobQuery<>();
        query1.addWhereEqualTo("collectUserID", BmobUser.getCurrentUser(_User.class).getObjectId());
        query1.findObjects(new FindListener<Collect>() {
            @Override
            public void done(List<Collect> object, BmobException e) {
                if (e == null) {
                    rc_collection.setLayoutManager(new LinearLayoutManager(MyCollectionActivity.this));
                    //rchealthyList.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL));
                    myCollectionAdapter=new MyCollectionAdapter(MyCollectionActivity.this,object);

                    rc_collection.setAdapter(myCollectionAdapter);
                } else {
                    Toast toast=Toast.makeText(MyCollectionActivity.this,"查询数据失败",Toast.LENGTH_LONG);
                    toast.show();
                }
            }
        });
    }
}
